import { signInAction } from "@/app/actions";
import { FormMessage, Message } from "@/components/form-message";
import { SubmitButton } from "@/components/submit-button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import Link from "next/link";

export default async function Login(props: { searchParams: Promise<Message> }) {
  const searchParams = await props.searchParams;
  return (
    <form className="flex-1 flex flex-col min-w-64">
      <h1 className="text-2xl font-medium text-white mb-2">登录</h1>
      <p className="text-sm text-white/70 mb-8">
        还没有账户？{" "}
        <Link className="text-white font-medium underline hover:text-white/80" href="/sign-up">
          注册
        </Link>
      </p>
      <div className="flex flex-col gap-4">
        <div>
          <Label htmlFor="email" className="text-white mb-2 block">邮箱</Label>
          <Input 
            name="email" 
            placeholder="your@example.com" 
            required 
            className="bg-white/20 border-white/30 text-white placeholder-white/50 focus:border-white/50 focus:ring-white/30"
          />
        </div>
        <div>
          <div className="flex justify-between items-center mb-2">
            <Label htmlFor="password" className="text-white">密码</Label>
            <Link
              className="text-xs text-white/70 underline hover:text-white/90"
              href="/forgot-password"
            >
              忘记密码？
            </Link>
          </div>
          <Input
            type="password"
            name="password"
            placeholder="您的密码"
            required
            className="bg-white/20 border-white/30 text-white placeholder-white/50 focus:border-white/50 focus:ring-white/30"
          />
        </div>
        <SubmitButton 
          pendingText="登录中..." 
          formAction={signInAction}
          className="bg-white/20 hover:bg-white/30 text-white border-white/30 mt-4"
        >
          登录
        </SubmitButton>
        <FormMessage message={searchParams} />
      </div>
    </form>
  );
}
